<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :closable="true"
    :destroyOnClose="true"
    @cancel="handleCancel"
  >
    <a-form-model layout="vertical" ref="followForm" :model="form">
      <div>
        <comment-area ref="areaForm" v-on:followupOK="followupOK" @reload="reload" :category="category" :record="record" :parentMsgId="replyMsgId" :replyMsgUsername="replyMsgUsername"></comment-area>
        <a-form-item>
          <a-button
            html-type="submit"
            :loading="submitting"
            type="primary"
            @click="handleSubmitArea"
          >添加跟进</a-button>
        </a-form-item> 
        <comment-message ref="commentMessage" v-if="visible" :category="category" :typesId="record.id"></comment-message>
    </div>
    </a-form-model>
    <template slot="footer">
      <a-button  @click="handleCancel">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
import CommentArea from "./CommentArea";
import CommentMessage from "./CommentMessage";

export default {
  name: "CrmFollowup",
  components: {
    CommentArea,
    CommentMessage,
  },
  data() {
    return{
      title:'',
      width:1200,
      visible: false,
      submitting: false,
      url: {
          getFollowup: '/followup/list',
          create: '/followup/add',
      },
      replyMsgId: "",
      replyMsgUsername: "",
      category:'',
      form: {},
      record: {},
      model: {},
    }
  },
  methods: {
    open(record,category){
      this.category = category;
      this.record = record;
      this.model = Object.assign({}, record);
      this.visible = true;
      this.title = "跟进记录";
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleCancel() {
      this.close()
    },
    followupOK(){
      this.submitting = false;
    },
    reload() {
      this.$refs['commentMessage'].loadFollowupRecord(true);
    },
    //提交跟进记录,修改自己的category，表名即可
    handleSubmitArea(){
      this.submitting = true;
      this.$refs.areaForm.handleSubmit(this.category,this.record.id,this.url.create);
    },


  }
}
</script>